import { User } from "@/stream-user/schema.user";
import { ENUM_USER } from "@/stream-user/core.define";

import { ExtIdTuple, ExtUUidTuple } from "~/db.pg";
import { ENUM_ERROR } from "~/error";
import { Page, PageResult } from "~/search";
import { ConditionList } from "~/search.match";

export enum ENUM_STEP {
  NONE = -1,
  PEDDING = 1000,
  END,
  FAIL,
}

export type Response<T> = {
  code: ENUM_ERROR;
  data: T;
  message: string;
};

export type RestDto = {
  traceInfo: { traceId: string; action: string; path: string; traceIp: string };
  visitorId: User["uuid32"];
  visitorType: ENUM_USER;
};

export type Action<T> = {
  success: T | null;
  fail: (T & { message?: string }) | null;
};

export type ActionList<T> = {
  success: T[];
  fail: (T & { message?: string })[];
};

export type PageDto<T> = {
  page: Page;
  conditionList: ConditionList<T>;
};
export type PageData<T> = PageResult<T>;

export type PostDto<T> = { schema: T };
export type PostRes<T> = { entity: T };
export type PostMutiDto<T> = { schemaList: T[] };
export type PostMutiRes<T> = ActionList<T>;

export type PutDto<T> = PostDto<T>;
export type PutRes<T> = PostRes<T>;
export type PutMutiDto<T> = PostMutiDto<T>;
export type PutMutiRes<T> = PostMutiRes<T>;

export type DisableDto = { id: ExtIdTuple["id"] };
export type DisableRes = null;
export type DisableMutiDto = { ids: ExtIdTuple["id"][] };
export type DisableMutiRes = null;

export type DisableUUid32Dto = { uuid: ExtUUidTuple["uuid32"] };
export type DisableUUid32Res = null;
export type DisableUUid32MutiDto = { uuids: ExtUUidTuple["uuid32"][] };
export type DisableUUid32MutiRes = null;

/** 提取函数的请求参数 */
export type Dto<T> = T extends (dto: infer D) => any ? D : never;

/** 提取函数的返回值 */
export type Res<T> = T extends (dto: any) => infer R ? R : never;
